package com.itboye.mengwu.data.repository;

import java.lang.reflect.Type;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.google.gson.reflect.TypeToken;
import com.itboye.mengwu.data.interfaces.IAddGoods;
import com.itboye.mengwu.data.model.GoodsListModel;
import com.itboye.mengwu.data.model.MyTiezibean;
import com.itboye.core.interfaces.ICompleteListener;
import com.itboye.core.utils.BaseErrorListener;
import com.itboye.core.utils.BaseSuccessReqListener;
import com.itboye.core.utils.ByJsonRequest.Builder;

public class AddGoodsRepository extends BaseNetRepository implements
		IAddGoods<GoodsListModel> {
	String api = "100";
	public static final String GoodsQuery = "BY_Product_query";// 5.1 商品分页查询
	public static final String GoodsAddCollection = "BY_Product_favorites";// 5.4
																			// 收藏
																			// 和
																			// 取消
	public static final String CollectionGoodsQuery = "BY_Product_getFavorites";// 5.5
																				// 收藏商品分页（分页查询）
	public static final String onshoucang = "BY_ForumThread_favorites";// 5.5
																		// 收藏商品分页（分页查询）

	public static final String MyTieZi = "BY_BbsUserCenter_queryThread";// 我的帖子

	public AddGoodsRepository(ICompleteListener listener) {
		// TODO Auto-generated constructor stub
		super(listener);
	}

	@Override
	public void add(GoodsListModel model) {
		// TODO Auto-generated method stub

	}

	@Override
	public void delete(GoodsListModel model) {
		// TODO Auto-generated method stub

	}

	@Override
	public void update(GoodsListModel model) {
		// TODO Auto-generated method stub

	}

	@Override
	public void getInfo(GoodsListModel model) {
		// TODO Auto-generated method stub
		Type type = new TypeToken<GoodsListModel>() {
		}.getType();
		String apiVer = api;
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("order", model.getOrder());
		map.put("min_cost", model.getMin_cost());
		map.put("max_cost", model.getMax_cost());
		map.put("page_no", model.getPage_no());
		map.put("name", model.getName());
		map.put("service_id", model.getService_id());
		// map.put("pid", pid);
		// map.put("count", count);
		// map.put("psku_id", psku_id);
		(new Builder<GoodsListModel>())
				.setTypeVerParamsAndReturnClass(GoodsQuery, apiVer, map, type)
				.requestListener(
						new BaseSuccessReqListener<GoodsListModel>(
								getListener()))
				.errorListener(new BaseErrorListener(getListener()))
				.desEncodeThenBuildAndSend();
	}

	@Override
	public List<GoodsListModel> queryYouHuiQuan(GoodsListModel model) {

		return null;
	}

	/**
	 * 添加 进收藏
	 */
	@Override
	public void addCollection(String uid, String pid, int values) {
		String apiVer = api;
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("uid", uid);
		map.put("pid", pid);
		map.put("favorite_value", values);
		(new Builder<String>())
				.setTypeVerParamsAndReturnClass(GoodsAddCollection, apiVer,
						map, String.class)
				.requestListener(
						new BaseSuccessReqListener<String>(getListener()))
				.errorListener(new BaseErrorListener(getListener()))
				.desEncodeThenBuildAndSend();
	}

	@Override
	public void queryCollectionGoods(String uid, String pageNo, String pageSize) {
		// TODO Auto-generated method stub
		Type type = new TypeToken<GoodsListModel>() {
		}.getType();
		String apiVer = api;
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("uid", uid);
		// map.put("page_no", page_no);
		// map.put("page_size", page_size);
		(new Builder<GoodsListModel>())
				.setTypeVerParamsAndReturnClass(CollectionGoodsQuery, apiVer,
						map, type)
				.requestListener(
						new BaseSuccessReqListener<GoodsListModel>(
								getListener()))
				.errorListener(new BaseErrorListener(getListener()))
				.desEncodeThenBuildAndSend();
	}

	@Override
	public void MyTieziShouCang(String uid, String tid, int favorite_value) {
		// TODO Auto-generated method stub
		Type type = new TypeToken<String>() {
		}.getType();
		String apiVer = api;
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("uid", uid);
		map.put("tid", tid);
		map.put("favorite_value", favorite_value);
		(new Builder<String>())
				.setTypeVerParamsAndReturnClass(onshoucang, apiVer, map, type)
				.requestListener(
						new BaseSuccessReqListener<String>(getListener()))
				.errorListener(new BaseErrorListener(getListener()))
				.desEncodeThenBuildAndSend();

	}

	@Override
	public void MyTieZi(String uid) {
		// TODO Auto-generated method stub
		Type type = new TypeToken<MyTiezibean>() {
		}.getType();
		String apiVer = api;
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("uid", uid);
		// map.put("page_no", page_no);
		// map.put("page_size", page_size);
		(new Builder<MyTiezibean>())
				.setTypeVerParamsAndReturnClass(MyTieZi, apiVer, map, type)
				.requestListener(
						new BaseSuccessReqListener<MyTiezibean>(getListener()))
				.errorListener(new BaseErrorListener(getListener()))
				.desEncodeThenBuildAndSend();
	}

}
